var backColor;
var headColor;
var resultsColor;
var locationUrl;
var styleUrl;
function getMovieName(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
   }
   else {
       return document[movieName]
   }
}
function callExternalInterface() {
	var backColor = "333333";
	var headColor = "FF9900";
	var resultsColor = "0EC5FF";
	var linkColor = "00FFF0";
	if ($("#backColor").attr("value")) {
		backColor = $("#backColor").attr("value");
		}
	if ($("#headColor").attr("value")) {
		headColor = $("#headColor").attr("value");
		}
	if ($("#resultsColor").attr("value")) {
		resultsColor = $("#resultsColor").attr("value");
		}
	if ($("#linkColor").attr("value")) {
		linkColor = $("#linkColor").attr("value");
		}
	getMovieName("colorsetter").sendColoursToFlash(backColor, headColor, resultsColor, linkColor);//.callPlayBall(inputValue.x.value, inputValue.y.value, inputValue.spd.value); ExternalInterface.addCallback("sendColoursToFlash", null, playBall(tgX:Number, tgY:Number, spd:Number));
}
function showMessage() {

}
function setDefaults() {
$("#sizeWidth").attr("value", "200");
$("#sizeHeight").attr("value", "400");
$("#locationUrl").attr("value", "http://tada.mcmaster.ca/wikita/pub/Main/FlashTAT/TAToo1.swf");
$("#backColor").attr("value", "");
$("#headColor").attr("value", "");
$("#resultsColor").attr("value", "");
$("#linkColor").attr("value", "");
}
function generateHTML() {
	//callExternalInterface();
	$("#resultsDiv2 h3").text("Click in text area and press Ctrl+C to copy.");
	$("#resultsDiv3 h3").text("Add the generated CSS to the stylesheet defined.");
	//if split at "://" yields on in item in the array, then remind user to include http:
	saveValues();
	var paramOptions = '<param name="TATOptions" value="';
	
	if (headColor) paramOptions += 'header-color:'+headColor+';';
	if (resultsColor) paramOptions += 'results-header-color:'+resultsColor+';';
	if (backColor) paramOptions += 'background-color:'+backColor+';';
	//if (linkColor) paramOptions += 'link-color:'+linkColor+';'; }
	paramOptions += '" />';
	if (paramOptions == '<param name="TATOptions" value="" />') paramOptions = "";
	
	var inputCode = '<object width="' + $("#sizeWidth").attr("value") + '" height="'+ $("#sizeHeight").attr("value")+ '"><param name="src" value="'	+locationUrl+'"  />'+paramOptions+'<embed src="'+$("#locationUrl").attr("value")+'" allowscriptaccess="always" quality="high"  type="application" width="' + $("#sizeWidth").attr("value") + '" height="' + $("#sizeHeight").attr("value") + '"></embed></object>';
	
	$("#codeOutput").attr("value", inputCode);

	$("#afterGenerate").text("Copy the text above and paste in your HTML code.").css("color", "darkRed").css("font-weight","bold");
}

function saveValues() {
	backColor = $("#backColor").attr("value");
	headColor = $("#headColor").attr("value");
	resultsColor = $("#resultsColor").attr("value");
	//linkColor = $("#linkColor").attr("value");
	locationUrl = $("#locationUrl").attr("value");
}

$(document).ready(function(){
	setDefaults();
	$("#advancedOptions .settingsCat, #advancedOptions .divider").toggle();
	$("#codeOutput").click( function() {
		$("#codeOutput").focus();
		$("#codeOutput").select(); 
	})
	$("#defaultsLink").click( function() {
		setDefaults();
		})
	$(".divider").click( function() {
		saveValues();
		$("#advancedOptions .settingsCat, #advancedOptions .divider").slideToggle("slow");
		})
	$("#previewLink").click( function() {
		callExternalInterface();
		})
	$("#generateLink").click( function() {
		generateHTML();
		saveValues();
		})
 });